﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Filters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace RepositorySys.Filte
{
    /// <summary>
    /// 过滤器
    /// 
    /// 作用：拦截非登录后请求
    /// </summary>
    public class CustomActionFilte : Attribute, IActionFilter
    {
        public void OnActionExecuted(ActionExecutedContext context)
        {
        }

        public void OnActionExecuting(ActionExecutingContext context)
        {
            if (String.IsNullOrEmpty(context.HttpContext.Session.GetString("userName")))
            {
                context.HttpContext.Response.Redirect("/Login/Index");
            }
        }
    }
}
